#include "corridor.h"
#include <assert.h>
#include <stdlib.h>
#include "util/mt.h"

#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
#ifndef MAX
#define MAX(a,b) ((a)>(b)?(a):(b))
#endif

void room_corridor_layout (Segment* segment, Layout* layout, Generator* generator)
{
	int length = MAX(3, (segment->n_roots + segment->n_branches + 1)/2*3 - 2);
	int width = 3;
	int height = 3;
	
	if (mt_rand () % 2) {
		width = length;
	} else {
		height = length;
	}
	
	int root[MAX_ROOTS];
	int n_roots = 0;
	
	for (int i = 0; i < segment->n_roots; i++)
	{
		assert(segment->root[i]->n_rooms > 0);
		root[n_roots++] = segment->root[i]->room[0];
	}
	
	segment->room[0] = generator->gen_room (layout, width, height, root, n_roots);
	segment->n_rooms = 1;
}

void room_corridor_content (Segment* segment, Layout* layout, Map* map,
                            Coord* entrance, int n_entrances,
                            Coord* exit, int n_exits)
{
	// Corridor has no room content
}
